// https://leetcode.cn/problems/jump-game/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    bool canJump(vector<int>& nums) {
        int maxPosition = 0;

        for (int i = 0; i < nums.size(); i++) {
            if (i <= maxPosition) {
                maxPosition = max(maxPosition, i + nums[i]);
                
                if (maxPosition >= nums.size() - 1) return true;
            }
        }
        return false;
    }
};